/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;


/**
 *
 * @author MrDoanCoi
 */
import DAL.MyConnectUnit;
import DTO.LoanType;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;
    
public class BLoanType {
    MyConnectUnit connect;
    private LoanType loanType;
     public BLoanType() {
        this.connect = DAL.DAL.getDAL();
    }
        public HashSet<LoanType>getLoanTypes(String condition, String OderBy) throws Exception{
        ResultSet result = this.connect.Select("LoanType",condition,OderBy);
        HashSet<LoanType> loantypes = new HashSet<LoanType>();
        while(result.next()){
            LoanType loantype = new LoanType();
            loantype.setLoanTypeID(result.getInt("LoanTypeID"));
            loantype.setDescription(result.getString("Description"));
       
            
            loantypes.add(loanType);
        }
        return loantypes;
    }
          public HashSet<LoanType>getLoanTypes(String condition) throws Exception{
        return getLoanTypes(condition,null);
    }
  public HashSet<LoanType>getLoanTypes() throws Exception{
        return getLoanTypes(null);
    }
    
       public LoanType getByID(int id)throws Exception{
        HashSet<LoanType>loantypes = this.getLoanTypes("LoanTypeID = "+ id);
        if(loantypes.size()>0)
            return loantypes.toArray(new LoanType[loantypes.size()])[0];
        return null;
       
   }
         public void Insert(LoanType  loantype)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("LoanTypeID", loantype.getLoanTypeID());
        map.put("Description", loantype.getDescription());
        
        this.connect.Insert("LoanType", map);
       
   }
         public void Inserts(HashSet<LoanType> loantypes)throws Exception{
        for(LoanType loantype:loantypes)
            this.Insert(loantype);
       
   }
          public void Update(LoanType loantype)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("Description", loantype.getDescription());
        this.connect.Update("LoanType", map,"LoanTypeID="+loantype.getLoanTypeID());
       
   }
            public void Updates(HashSet<LoanType> loantypes)throws Exception{
        for(LoanType loantype:loantypes)
            this.Update(loantype);
}
      public void Delete(LoanType loantype) throws Exception{
        this.connect.Delete("LoanType", "LoanTypeID="+loantype.getLoanTypeID());
    }
       public void Deletes(HashSet<LoanType> loantypes) throws Exception {
        for(LoanType loantype:loantypes)
            this.Delete(loantype);
   }        
            
}

